package com.woniu.service.impl;

import com.woniu.outlet.dao.PurchasePoMapper;
import com.woniu.outlet.po.PurchasePo;
import com.woniu.outlet.po.PurchasePoExample;
import com.woniu.service.PurchasePoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 采购单查询业务类
 */
@Service
public class PurchasePoServiceImpl implements PurchasePoService {

    @Autowired
    private PurchasePoMapper purchasePoMapper;

    /**
     * 采购单查询
     * @param po
     * @return
     */
    public List<PurchasePo> findAllPurchase(PurchasePo po){
        PurchasePoExample purchasePoExample = new PurchasePoExample();
        PurchasePoExample.Criteria criteria = purchasePoExample.createCriteria();

        if (!StringUtils.isEmpty(po.getPurchaseNo())){
            criteria.andPurchaseNoEqualTo(po.getPurchaseNo());
        }
        if (!StringUtils.isEmpty(po.getId())){
            criteria.andIdEqualTo(po.getId());
        }
        if (!StringUtils.isEmpty(po.getCustomerId())){
            criteria.andCustomerIdEqualTo(po.getCustomerId());
        }
        List<PurchasePo> purchasePos = purchasePoMapper.selectByExample(purchasePoExample);
        return purchasePos;
    }

    /**
     * 根据id查询单个采购单
     * @param id
     * @return
     */
    public PurchasePo getPurchaeById(Long id) {
        PurchasePo purchasePo = purchasePoMapper.selectByPrimaryKey(id);
        return purchasePo;
    }
}
